<template>
  <view>
    <view class="flex flex-justify-between mx-4 my-2rpx flex-items-center">
      <text class="text-lg font-size-3 font-800">数据上传</text>
    </view>
    <FormCore :fields="formFields" :initial-values="formData" @submit="submit"></FormCore>
  </view>
</template>

<script lang="ts" setup>
import { ref, reactive, computed, onMounted, watch } from 'vue'
import FormCore from '../components/FormCore.vue'
import type { FormField } from '../components/types'
const formData = ref({})
onMounted(() => {
  const savedData = uni.getStorageSync('formDataKC')
  if (savedData) {
    formData.value = savedData._value
  }
})

const formFields: FormField[] = [
  //   {
  //     fieldType: 'date',
  //     name: 'dateTime',
  //     prop: 'dateTime',
  //     label: '勘察日期',
  //     placeholder: '请选择勘察日期',
  //     rules: [{ required: true, message: '必填字段' }]
  //   },
  {
    fieldType: 'upload',
    name: 'guoshu',
    prop: 'guoshu',
    label: '果蔬库',
    iskai: true,
    uploadConfig: {
      action: 'https://mockapi.eolink.com/zhTuw2P8c29bc981a741931bdd86eb04dc1e8fd64865cb5/upload',
      maxCount: 5,
      accept: 'all'
    },
    rules: [{ required: true, message: '必填字段' }]
  },
  {
    iskai: true,
    fieldType: 'upload',
    name: 'bingxian',
    prop: 'bingxian',
    label: '冰鲜库',
    uploadConfig: {
      action: 'https://mockapi.eolink.com/zhTuw2P8c29bc981a741931bdd86eb04dc1e8fd64865cb5/upload',
      maxCount: 5,
      accept: 'all'
    },
    rules: [{ required: true, message: '必填字段' }]
  },
  {
    iskai: true,
    fieldType: 'upload',
    name: 'zhongwen',
    prop: 'zhongwen',
    label: '中温库',
    uploadConfig: {
      action: 'https://mockapi.eolink.com/zhTuw2P8c29bc981a741931bdd86eb04dc1e8fd64865cb5/upload',
      maxCount: 5,
      accept: 'all'
    },
    rules: [{ required: true, message: '必填字段' }]
  },
  {
    iskai: true,
    fieldType: 'upload',
    name: 'lengdong',
    prop: 'lengdong',
    label: '冷冻库',
    uploadConfig: {
      action: 'https://mockapi.eolink.com/zhTuw2P8c29bc981a741931bdd86eb04dc1e8fd64865cb5/upload',
      maxCount: 5,
      accept: 'all'
    },
    rules: [{ required: true, message: '必填字段' }]
  },
  {
    fieldType: 'switch',
    name: 'guoshufj',
    prop: 'guoshufj',
    label: '果蔬库风机是否同启'
  },
  {
    fieldType: 'input',
    name: 'guoshuSL',
    prop: 'guoshuSL',
    label: '果蔬库风机数量',
    placeholder: '请果蔬库风机数量'
  }
]
const submit = ({ formRef, formData }) => {
  uni.setStorageSync('formDataKC', formData)
}
</script>

<style lang="scss" scoped></style>
